package com.itboye.textileexpres.top;

import imagedemo.ImagePagerActivity;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.textileexpres.widget.DertailServProduct_attr;
import com.example.textileexpres.widget.FlowLayout;
import com.itboye.textileexpes.beans.DetailBean;
import com.itboye.textileexpes.beans.GoodsDetailBean;
import com.itboye.textileexpes.beans.ShopCartModel;
import com.itboye.textileexpes.presenter.GoodsPresenter;
import com.itboye.textileexpes.presenter.ShopCartPresenter;
import com.itboye.textileexpres.R;
import com.itboye.textileexpres.base.BaseActivity;
import com.itboye.textileexpres.base.ResultEntity;
import com.itboye.textileexpres.login.LoginActivity;
import com.itboye.textileexpres.main.MainActivity;
import com.itboye.textileexpres.myset.ActivityCustomerService;
import com.itboye.textileexpres.util.BaseDialogFragment;
import com.itboye.textileexpres.util.DensityUtil;
import com.itboye.textileexpres.util.IsMobileNumPhone;
import com.itboye.textileexpres.util.PriceChange;
import com.itboye.textileexpres.util.TimeFormat;
import com.itboye.textileexpres.util.XImageLoader;
import com.itboye.textileexpres.widget.CarouselView;
import com.itboye.textileexpres.widget.DertailServiceDialog;
import com.itboye.textileexpres.widget.RoundImageView;
import com.itboye.textileexpres.widget.XScrollView;
import com.itboye.textileexptes.config.GlobalConfig;
import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.Animator.AnimatorListener;
import com.nineoldandroids.animation.ObjectAnimator;
import com.tencent.connect.share.QQShare;
import com.tencent.mm.sdk.modelmsg.SendMessageToWX;
import com.tencent.mm.sdk.modelmsg.WXMediaMessage;
import com.tencent.mm.sdk.modelmsg.WXWebpageObject;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
import com.tencent.tauth.UiError;

/**
 * 商品详情
 */
public class GoodsDetail extends BaseActivity implements Observer,
		OnClickListener {
	ImageView back;
	TextView title;
	ImageView img_other;
	ImageView img_search;
	PopupWindow popupWindow;
	PopupWindow window;
	TextView share_tv, new_tv, main_tv;
	LinearLayout shopcart_lin, buy_lin, order_lin, custom_lin;
	CarouselView topLunbo;
	private List<ImageView> bmps;
	TextView publish_time, Publish_people_name, collect_num, goods_num,
			goods_name, goods_detail, price_1_tv, limit_1, price_2_tv, limit_2,
			price_3_tv, limit_3, address_tv, color_tv, type_tv, service_tv,
			choose_tv;
	TextView product_attr, pinpai_tv, huohao_tv, caizhi_tv;
	LinearLayout sercice_lin, product_attr_liner;
	RoundImageView person_img;
	TextView name, phone;
	String pid;
	RelativeLayout top_rel;
	GoodsPresenter presenter;
	GoodsDetailBean detailBean;
	double total;
	int totalNum;
	String type;
	StringBuffer descid;
	StringBuffer moreCount;
	ScrollView scroll;
	LinearLayout bottom;
	ShopCartPresenter shopCartPresenter;
	View pop;
	static final String WXAPPID = "wx641da6617a5f5f67";
	static final String url = "http://api.guannan.itboye.com/public/web.php/Web/app_share?pid=";
	private String QQAPP_ID = "1105844486";
	Tencent mTencent;

	private int i;// 查看大图的轮播

	// ActivityCollectionEdit

	@Override
	public int initView() {
		return R.layout.activity_goodsdetail;
	}

	@Override
	public void onMyCreate() {
		WindowManager wm = this.getWindowManager();

		int width = wm.getDefaultDisplay().getWidth();
		int height = wm.getDefaultDisplay().getHeight();
		System.out.println("widthheight" + height / 3);
		title.setText(getResources().getString(R.string.h57));
		pid = getIntent().getStringExtra("pid");
		showProgressDialog(getString(R.string.cu_xsearch_loading), true);
		mTencent = Tencent.createInstance(QQAPP_ID,
				this.getApplicationContext());
		scroll.setVisibility(View.GONE);
		bottom.setVisibility(View.GONE);
		presenter = new GoodsPresenter(this);
		shopCartPresenter = new ShopCartPresenter(this);
		presenter.DetailQuery("" + pid);
		Log.e("detaile", pid + "");
		img_search.setImageResource(R.drawable.goods_shopcart);

	}

	@Override
	public void onClick(View v) {

		Intent intent = null;
		switch (v.getId()) {
		case R.id.back:
			finish();
			break;
		case R.id.img_search:// 购物车
			// intent = new Intent(GoodsDetail.this,
			// ActivityCustomerDetail.class);
			// startActivity(intent);
			intent = new Intent("gotoshopcart");
			intent.putExtra("index", 2);
			sendBroadcast(intent);
			finish();
			break;
		case R.id.img_other:// ...
			View popView = LayoutInflater.from(GoodsDetail.this).inflate(
					R.layout.pop_goods_detail, null);
			share_tv = (TextView) popView.findViewById(R.id.share_tv);
			new_tv = (TextView) popView.findViewById(R.id.news_tv);
			main_tv = (TextView) popView.findViewById(R.id.main_tv);
			share_tv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {

					// Toast(GoodsDetailsActivity.this, "share");
					Onshare();
					popupWindow.dismiss();
				}

			});
			new_tv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {

					Intent intent = new Intent(GoodsDetail.this,
							ActivityCustomerService.class);
					startActivity(intent);
					popupWindow.dismiss();
					// finish();

				}
			});
			main_tv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {

					Intent intent = new Intent(GoodsDetail.this,
							MainActivity.class);
					startActivity(intent);
					popupWindow.dismiss();
					finish();
				}
			});
			popupWindow = new PopupWindow(popView, ChangeToDP(100),
					LayoutParams.WRAP_CONTENT);
			popupWindow.setOutsideTouchable(true);
			popupWindow.setBackgroundDrawable(new BitmapDrawable());
			popupWindow.showAsDropDown(v);

			break;
		case R.id.color_tv:// 规格选择
			type = "color";
			new JiaRuGouWuCheDialog().show(getSupportFragmentManager(), "");
			break;
		case R.id.custom_lin:// 消息
			intent = new Intent(GoodsDetail.this, ActivityCustomerService.class);
			startActivity(intent);
			break;
		case R.id.shopcart_lin:// 加入购物车
			type = "shopcar";
			new JiaRuGouWuCheDialog().show(getSupportFragmentManager(), "");
			break;
		case R.id.order_lin:// 线下订单
			type = "order";
			new JiaRuGouWuCheDialog().show(getSupportFragmentManager(), "");
			break;
		case R.id.buy_lin:// 立即购买
			type = "lijibuy";
			new JiaRuGouWuCheDialog().show(getSupportFragmentManager(), "");
			break;

		default:
			break;
		}
	}

	/**
	 * 分享到
	 */
	private void Onshare() {
		LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.item_addd_share, null);
		window = new PopupWindow(view, WindowManager.LayoutParams.MATCH_PARENT,
				WindowManager.LayoutParams.WRAP_CONTENT);
		window.setFocusable(true);
		window.setBackgroundDrawable(new BitmapDrawable());
		window.showAtLocation(findViewById(R.id.bottom), Gravity.BOTTOM, 0, 0);
		ImageView shareqq = (ImageView) view.findViewById(R.id.shareQQ);
		shareqq.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				onQQ();
			}

		});
		ImageView shareWeiXinHaoYou = (ImageView) view
				.findViewById(R.id.shareWeChat);
		shareWeiXinHaoYou.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				onPengYou();
			}

		});
		ImageView imgSharePengYouQuan = (ImageView) view
				.findViewById(R.id.imgSharePengYouQuan);
		imgSharePengYouQuan.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				onPengYouQuan();
			}

		});
	}

	/**
	 * 分享到QQ
	 */
	private void onQQ() {

		final Bundle params = new Bundle();
		params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE,
				QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
		params.putString(QQShare.SHARE_TO_QQ_TITLE, "TextileExpress");
		params.putString(QQShare.SHARE_TO_QQ_SUMMARY,
				"我在TextileExpress发现了一个好玩的东西，速来围观");
		params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, url + pid);
		params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL,
				GlobalConfig.IMAGE_DOUBLE + detailBean.getMain_img());
		params.putString(QQShare.SHARE_TO_QQ_APP_NAME, "TextileExpress");
		mTencent.shareToQQ(GoodsDetail.this, params, new IUiListener() {

			@Override
			public void onError(UiError arg0) {

				Toast.makeText(getApplicationContext(), "分享失败，请重试", 0).show();
			}

			@Override
			public void onComplete(Object arg0) {

				Toast.makeText(getApplicationContext(), "分享完成", 0).show();
			}

			@Override
			public void onCancel() {

				Toast.makeText(getApplicationContext(), "已取消", 0).show();
			}
		});
	}

	/**
	 * 分享微信
	 */
	private void onPengYou() {

		final IWXAPI api = WXAPIFactory.createWXAPI(this, WXAPPID, true);
		api.registerApp(WXAPPID);
		api.openWXApp();
		WXWebpageObject webpage = new WXWebpageObject();
		webpage.webpageUrl = "" + url + pid;
		WXMediaMessage msg = new WXMediaMessage(webpage);
		msg.title = "TextileExpress";
		msg.description = "我在TextileExpress发现了一个好玩的东西，速来围观";
		SendMessageToWX.Req req = new SendMessageToWX.Req();
		req.transaction = "webpage";
		req.message = msg;
		req.scene = SendMessageToWX.Req.WXSceneSession;
		api.sendReq(req);
	}

	/**
	 * 分享到朋友圈
	 */
	private void onPengYouQuan() {

		final IWXAPI api = WXAPIFactory.createWXAPI(this, WXAPPID, true);
		api.registerApp(WXAPPID);
		api.openWXApp();
		WXWebpageObject webpage = new WXWebpageObject();
		webpage.webpageUrl = "" + url + pid;
		WXMediaMessage msg = new WXMediaMessage(webpage);
		msg.title = "TextileExpress";
		msg.description = "我在TextileExpress发现了一个好玩的东西，速来围观";
		// Bitmap thumb = BitmapFactory.decodeResource(
		// getResources(), R.drawable.logo);
		// msg.thumbData=Util.bmpToByteArray(thumb,true);
		SendMessageToWX.Req req = new SendMessageToWX.Req();
		req.transaction = "webpage";
		req.message = msg;
		req.scene = SendMessageToWX.Req.WXSceneTimeline;
		api.sendReq(req);

	}

	@Override
	public void update(Observable observable, Object data) {

		ResultEntity entity = handlerError(data);
		if (entity != null) {
			if (entity.getEventType() == GoodsPresenter.Detail_success) {
				detailBean = (GoodsDetailBean) entity.getData();
				if (detailBean.getId() == null || "".equals(detailBean.getId())) {
					scroll.setVisibility(View.GONE);
					bottom.setVisibility(View.GONE);
				} else {
					try {
						closeProgressDialog();
					} catch (Exception e) {

					}
					scroll.setVisibility(View.VISIBLE);
					bottom.setVisibility(View.VISIBLE);
					onBaner();
				}

			} else if (entity.getEventType() == GoodsPresenter.Detail_fail) {
				scroll.setVisibility(View.GONE);
				bottom.setVisibility(View.GONE);
				finish();
			}
			if (entity.getEventType() == ShopCartPresenter.MoreShopCartSuccessEvent) {
				Intent intent = new Intent("updateshopcar");
				sendBroadcast(intent);
				toast(getString(R.string.h1186));
			} else if (entity.getEventType() == ShopCartPresenter.MoreShopCartFailureEvent) {
				toast("" + entity.getData());
			}
		} else {
			scroll.setVisibility(View.GONE);
			bottom.setVisibility(View.GONE);
		}
	}

	private void onBaner() {

		product_attr.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (detailBean.getProperties() == null
						|| detailBean.getProperties().equals("")) {
					toast(getString(R.string.h1202));// 无属性
				} else {
					new DertailServProduct_attr(GoodsDetail.this, detailBean)
							.show(getSupportFragmentManager(), "");
				}
			}
		});
		service_tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if (detailBean.getCan_mixed_batch() == null
						|| detailBean.getCan_mixed_batch().equals("")) {
					toast(getString(R.string.h1203));// 无说明
				} else {
					new DertailServiceDialog(GoodsDetail.this, detailBean)
							.show(getSupportFragmentManager(), "");
				}
			}
		});
		if (detailBean.getCan_mixed_batch() != null
				&& "1".equals(detailBean.getCan_mixed_batch())) {
			View view = LayoutInflater.from(GoodsDetail.this).inflate(
					R.layout.item_service, null);
			TextView tv = (TextView) view.findViewById(R.id.tv);
			tv.setText(getString(R.string.h1172));
			sercice_lin.addView(view);

		}
		if (detailBean.getHas_receipt() != null
				&& "1".equals(detailBean.getHas_receipt())) {
			View view = LayoutInflater.from(GoodsDetail.this).inflate(
					R.layout.item_service, null);
			TextView tv = (TextView) view.findViewById(R.id.tv);
			tv.setText(getString(R.string.h1173));
			sercice_lin.addView(view);

		}
		if (detailBean.getHas_sample() != null
				&& "1".equals(detailBean.getHas_sample())) {
			View view = LayoutInflater.from(GoodsDetail.this).inflate(
					R.layout.item_service, null);
			TextView tv = (TextView) view.findViewById(R.id.tv);
			tv.setText(getString(R.string.h1174));
			sercice_lin.addView(view);

		}
		if (detailBean.getSupport_replace() != null
				&& "1".equals(detailBean.getSupport_replace())) {
			View view = LayoutInflater.from(GoodsDetail.this).inflate(
					R.layout.item_service, null);
			TextView tv = (TextView) view.findViewById(R.id.tv);
			tv.setText(getString(R.string.h1175));
			sercice_lin.addView(view);

		}
		if (detailBean.getUnder_guaranty() != null
				&& "1".equals(detailBean.getUnder_guaranty())) {
			View view = LayoutInflater.from(GoodsDetail.this).inflate(
					R.layout.item_service, null);
			TextView tv = (TextView) view.findViewById(R.id.tv);
			tv.setText(getString(R.string.h1178));
			sercice_lin.addView(view);

		}
		if (detailBean.getConsignment_time() != null
				&& "1".equals(detailBean.getConsignment_time())) {
			View view = LayoutInflater.from(GoodsDetail.this).inflate(
					R.layout.item_service, null);
			TextView tv = (TextView) view.findViewById(R.id.tv);
			tv.setText(getString(R.string.h1176));
			sercice_lin.addView(view);

		}
		publish_time
				.setText(TimeFormat.DateFormat(detailBean.getExpire_time()));
		Publish_people_name.setText(":" + detailBean.getContact_name() + "");
		name.setText("" + detailBean.getContact_name() + "");
		collect_num.setText(getString(R.string.h1177) + "："
				+ detailBean.getFavorite_cnt() + "");
		goods_num.setText(getString(R.string.h2) + ":"
				+ detailBean.getProduct_code() + "");
		goods_name.setText(detailBean.getName() + "");
		goods_detail.setText(detailBean.getSynopsis() + "");
		phone.setText(getString(R.string.h106) + "："
				+ detailBean.getContact_way());
		Log.e("hu....skulist", detailBean.getSku_list() + "");
		if (detailBean.getSku_list().size() != 0) {
			limit_1.setText("" + detailBean.getSku_list().get(0).getCnt1()
					+ getString(R.string.h1179));
			limit_2.setText("" + detailBean.getSku_list().get(0).getCnt2()
					+ "-" + detailBean.getSku_list().get(0).getCnt3());
			limit_3.setText(">" + detailBean.getSku_list().get(0).getCnt3()
					+ "");
		}

		if (detailBean.getSku_list().size() != 0) {
			if ("".equals(detailBean.getSku_list().get(0).getCnt2())
					|| "0".equals(detailBean.getSku_list().get(0).getCnt2())
					|| detailBean.getSku_list().get(0).getCnt2() == null) {
				price_2_tv.setVisibility(View.GONE);
				limit_2.setVisibility(View.GONE);
				limit_1.setText("" + detailBean.getSku_list().get(0).getCnt1()
						+ getString(R.string.h1179));
				limit_2.setText("" + detailBean.getSku_list().get(0).getCnt2()
						+ "-" + detailBean.getSku_list().get(0).getCnt3());
				limit_3.setText(">" + detailBean.getSku_list().get(0).getCnt3()
						+ "");
			}
			if ("".equals(detailBean.getSku_list().get(0).getCnt3())
					|| "0".equals(detailBean.getSku_list().get(0).getCnt3())) {
				if (!"".equals(detailBean.getSku_list().get(0).getCnt2())
						&& !"0".equals(detailBean.getSku_list().get(0)
								.getCnt2())
						&& detailBean.getSku_list().get(0).getCnt2() != null) {
					limit_2.setVisibility(View.VISIBLE);
					limit_2.setText("≥"
							+ detailBean.getSku_list().get(0).getCnt2());
					limit_1.setText(""
							+ detailBean.getSku_list().get(0).getCnt1()
							+ getString(R.string.h1179));
					limit_3.setText("≥"
							+ detailBean.getSku_list().get(0).getCnt3());
				}
				price_3_tv.setVisibility(View.GONE);
				limit_3.setVisibility(View.GONE);
				limit_1.setText("" + detailBean.getSku_list().get(0).getCnt1()
						+ getString(R.string.h1179));
				limit_3.setText("≥" + detailBean.getSku_list().get(0).getCnt3());
			}
			try {
				price_1_tv.setText(""
						+ PriceChange.Change(detailBean.getSku_list().get(0)
								.getPrice()));
				price_2_tv.setText(""
						+ PriceChange.Change(detailBean.getSku_list().get(0)
								.getPrice2()));
				price_3_tv.setText(""
						+ PriceChange.Change(detailBean.getSku_list().get(0)
								.getPrice3()));

			} catch (Exception e) {

			}

		} else {
			price_1_tv.setVisibility(View.GONE);
			limit_1.setVisibility(View.GONE);
			price_2_tv.setVisibility(View.GONE);
			limit_2.setVisibility(View.GONE);
			price_3_tv.setVisibility(View.GONE);
			limit_3.setVisibility(View.GONE);
		}

		address_tv.setText(getString(R.string.placeOrigin) + ":"
				+ detailBean.getPlace_origin() + "");
		/***
		 * 规格选择属性
		 */
		StringBuffer color = new StringBuffer();
		for (int i = 0; i < detailBean.getSku_info().size(); i++) {
			String desc = new String();
			desc = (detailBean.getSku_info().get(i).getSku_name());
			color.append(detailBean.getSku_info().get(i).getSku_name());

		}
		StringBuffer colorNmae = new StringBuffer();
		for (int c = 0; c < detailBean.getSku_info().size(); c++) {

			for (int d = 0; d < detailBean.getSku_info().get(c).getValue_list()
					.size(); d++) {
				colorNmae.append(detailBean.getSku_info().get(c)
						.getValue_list().get(d).getValue_name());
			}
		}

		color_tv.setText("" + color + "" + colorNmae);
		topLunbo = (CarouselView) findViewById(R.id.topLunbo);
		bmps = new ArrayList<ImageView>();
		for (i = 0; i < detailBean.getCarousel_images().size(); i++) {
			ImageView imageView = new ImageView(this);
			imageView.setScaleType(ScaleType.FIT_XY);

			com.nostra13.universalimageloader.core.ImageLoader.getInstance()
					.displayImage(
							GlobalConfig.IMAGE_DOUBLE
									+ detailBean.getCarousel_images().get(i),
							imageView);

			final ArrayList<String> urls2 = (ArrayList<String>) detailBean
					.getCarousel_images();

			imageView.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					System.out.println("urls2urls2urls2"
							+ GlobalConfig.IMAGE_DOUBLE + urls2);
					Intent intent = new Intent(GoodsDetail.this,
							ImagePagerActivity.class);
					// 图片url,为了演示这里使用常量，一般从数据库中或网络中获取
					intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS, urls2);
					intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_INDEX, i);
					startActivity(intent);

				}
			});
			bmps.add(imageView);

		}
		topLunbo.setImageBitmaps(bmps);
		for (int i = 0; i < 3; i++) {
			View view = LayoutInflater.from(GoodsDetail.this).inflate(
					R.layout.item_goods_shuxing, null);
			TextView tv1 = (TextView) view.findViewById(R.id.tv1);
			TextView tv2 = (TextView) view.findViewById(R.id.tv2);
			tv1.setText(detailBean.getProperties().get(i).getProp_name() + ":");
			tv2.setText(detailBean.getProperties().get(i).getProp_value_list()
					.get(0).getValue_name()
					+ "");
			product_attr_liner.addView(view);

		}
		XImageLoader.load(GlobalConfig.IMAGE_HEAD + detailBean.getUid(),
				person_img);
	}

	/**
	 * 购买弹框
	 */
	class JiaRuGouWuCheDialog extends BaseDialogFragment {
		View close;
		ImageView pic;
		TextView unit;
		TextView total_price, total_num2;
		TextView price;
		TextView qipi;
		TextView total_num1;
		ViewGroup guigeContainer;

		LinearLayout bottomss;// 三个布局
		LinearLayout gouwuche, xianxia, lijigoumai;// 加入购物车，线下，立即购买

		View ok;
		View jian;
		View jia;
		EditText input;
		boolean isLiJIGouMai;
		ViewGroup container, containergui;
		String imgUrl;
		protected String priceString;
		protected String skuId;
		List<String> pricelist = new ArrayList<String>();
		List<String> codelist = new ArrayList<String>();
		List<String> guigelist = new ArrayList<String>();
		List<String> countlist = new ArrayList<String>();
		List<String> imglist = new ArrayList<String>();
		ArrayList<TextView> hashMap = new ArrayList<TextView>();
		int num;
		double myprice;
		PopupWindow popupWindow;
		String singleNum;// 起批
		String myTotalp;

		TextView color_tv;
		TextView price_m;
		TextView kucuns;
		TextView jians;
		TextView jias;

		TextView inputs;// 数量
		ArrayList<FlowLayout> arFlowLayout = new ArrayList<>();
		private FlowLayout flowLayout;
		String tempSkuId = null;

		String kc;// 库存
		String qp;// 起批
		String jg;// 价格
		String dw;// 单位
		String tx;// 头像

		public JiaRuGouWuCheDialog() {

		}

		void DialogTopShow(int i) {

			price.setText(PriceChange.Change(detailBean.getSku_list().get(i)
					.getPrice()));
			XImageLoader.load(
					GlobalConfig.IMAGE_DOUBLE + detailBean.getMain_img(), pic);
			// detailBean.getSku_list().get(i).setSelected(true);
			// inputs.setText(detailBean.getSku_list().get(i).getCnt1() + "");

		}

		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {

			return LayoutInflater.from(GoodsDetail.this).inflate(
					R.layout.dialog_add_shopcart, null);
		}

		@Override
		public void onActivityCreated(Bundle savedInstanceState) {

			super.onActivityCreated(savedInstanceState);

			if (savedInstanceState != null) {
				// goodsDetailBeans = (GoodsDetailsRootBean) savedInstanceState
				// .getSerializable("goodsDetailBeans");
				// isLiJIGouMai = savedInstanceState.getBoolean("isLiJIGouMai");
			}
			if ("color".equals(type)) {
				ok.setVisibility(View.GONE);
				bottomss.setVisibility(View.VISIBLE);
			} else {
				ok.setVisibility(View.VISIBLE);
				bottomss.setVisibility(View.GONE);
			}

			if(detailBean.getSku_list().size()>0){
				kc = detailBean.getSku_list().get(0).getQuantity();
				qp = detailBean.getSku_list().get(0).getCnt1();
				jg = detailBean.getSku_list().get(0).getPrice();
				dw = detailBean.getSku_list().get(0).getUnit_name();
				tx = detailBean.getMain_img();
			}

			if (detailBean.getSku_list().size() != 0) {
				XImageLoader.load(
						GlobalConfig.IMAGE_DOUBLE + tx,pic);
				price.setText(PriceChange.Change(jg));
				inputs.setText(qp);
				unit.setText("/" + dw);
				qipi.setText("(" + qp + dw + "起批)");
				total_num1.setText(dw);

			} else {
				XImageLoader.load(
						GlobalConfig.IMAGE_DOUBLE + detailBean.getMain_img(),
						pic);
				price.setVisibility(View.GONE);
				unit.setVisibility(View.GONE);
			}
			addGuiGe();
			onKucun();

			gouwuche.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					ShopCartModel model = new ShopCartModel();
					descid = new StringBuffer();
					moreCount = new StringBuffer();
					for (int i = 0; i < detailBean.getSku_list().size(); i++) {
						if (detailBean.getSku_list().get(i).isSelected() == true) {
							descid.append(","
									+ detailBean.getSku_list().get(i)
											.getSku_pkid());

							pricelist.add(detailBean.getSku_list().get(i)
									.getPrice());
							codelist.add(detailBean.getSku_list().get(i)
									.getProduct_code());
							guigelist.add(detailBean.getSku_list().get(i)
									.getSku_desc());
							imglist.add(detailBean.getSku_list().get(i)
									.getSku_pkid());
							if (Integer.parseInt(inputs.getText().toString()
									.equals("") ? "0" : inputs.getText()
									.toString()) < Integer.parseInt(qp
									.equals("") ? "0" : qp)) {
								toast(getString(R.string.h1181));
								return;
							} else if (Integer.parseInt(inputs.getText()
									.toString().equals("") ? "0" : inputs
									.getText().toString()) > Integer
									.parseInt(kc.equals("") ? "0" : kc)) {
								toast(getString(R.string.h28));
								return;
							}
						}
					}
					for (int j = 0; j < hashMap.size(); j++) {
						if (detailBean.getSku_list().get(j).isSelected() == true) {
							moreCount.append(","
									+ hashMap.get(j).getText().toString() + "");
						}

					}
					if (codelist.size() == 0) {
						toast(getString(R.string.h1180));
						return;
					}
					model.setUid(IsMobileNumPhone.isUid());
					String guigeID = "";// 规格id
					List<String> xuanzhong = selectedGuige();
					// String xz=xuanzhong.toString();
					StringBuffer stringBuffer = new StringBuffer();
					if (xuanzhong != null) {
						for (String s1 : xuanzhong) {
							stringBuffer.append(s1 + ";");
						}
					}
					for (int sid = 0; sid < detailBean.getSku_list().size(); sid++) {
						String skuID = detailBean.getSku_list().get(sid)
								.getSku_id();
						String pkid = detailBean.getSku_list().get(sid)
								.getSku_pkid();
						if (skuID.equals(stringBuffer.toString())) {
							guigeID = pkid;
						}
					}
					// model.setSku_pkid(descid.substring(1,
					// descid.length()));
					model.setSku_pkid(guigeID);// 规格

					model.setId(detailBean.getId());
					model.setCount(moreCount.substring(1, moreCount.length()));
					shopCartPresenter.shopcartDuoAdd(model);
					dismiss();
				}

			});
			xianxia.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Intent intent = new Intent(GoodsDetail.this,
							ActivityYiXiangDingdan.class);
					TransportData(intent);
					dismiss();
				}
			});
			lijigoumai.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Intent intent = new Intent(GoodsDetail.this,
							ActivityBuyNow.class);
					TransportData(intent);
					dismiss();
				}
			});

			close.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					close();
				}
			});
			ok.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {

					if (IsMobileNumPhone.isUid() == null
							|| "".equals(IsMobileNumPhone.isUid())) {
						toast(getString(R.string.h1182));
						Intent intent = new Intent(GoodsDetail.this,
								LoginActivity.class);
						startActivity(intent);
						return;
					}
					String s = checkGuiGeSelectedState();
					if (s == null) {
						return;
					}
					if ("lijibuy".equals(type)) {
						Intent intent = new Intent(GoodsDetail.this,
								ActivityBuyNow.class);
						TransportData(intent);
						dismiss();
					} else if ("order".equals(type)) {
						Intent intent = new Intent(GoodsDetail.this,
								ActivityYiXiangDingdan.class);
						TransportData(intent);
						dismiss();
					} else if ("color".equals(type)) {
						StringBuffer buffer = new StringBuffer();
						for (int i = 0; i < detailBean.getSku_list().size(); i++) {
							if (detailBean.getSku_list().get(i).isSelected() == true) {
								buffer.append(","
										+ detailBean.getSku_list().get(i)
												.getSku_desc());
								color_tv.setText(buffer.substring(1,
										buffer.length()));
							}
						}
						dismiss();
					} else if ("shopcar".equals(type)) {
						ShopCartModel model = new ShopCartModel();
						descid = new StringBuffer();
						moreCount = new StringBuffer();
						for (int i = 0; i < detailBean.getSku_list().size(); i++) {
							if (detailBean.getSku_list().get(i).isSelected() == true) {
								descid.append(","
										+ detailBean.getSku_list().get(i)
												.getSku_pkid());

								pricelist.add(detailBean.getSku_list().get(i)
										.getPrice());
								codelist.add(detailBean.getSku_list().get(i)
										.getProduct_code());
								guigelist.add(detailBean.getSku_list().get(i)
										.getSku_desc());
								imglist.add(detailBean.getSku_list().get(i)
										.getSku_pkid());
								if (Integer.parseInt(inputs.getText()
										.toString().equals("") ? "0" : inputs
										.getText().toString()) < Integer
										.parseInt(qp.equals("") ? "0" : qp)) {
									toast(getString(R.string.h1181));
									return;
								} else if (Integer.parseInt(inputs.getText()
										.toString().equals("") ? "0" : inputs
										.getText().toString()) > Integer
										.parseInt(kc.equals("") ? "0" : kc)) {
									toast(getString(R.string.h28));
									return;
								}
							}
						}
						for (int j = 0; j < hashMap.size(); j++) {
							if (detailBean.getSku_list().get(j).isSelected() == true) {
								moreCount.append(","
										+ hashMap.get(j).getText().toString()
										+ "");
							}

						}
						if (codelist.size() == 0) {
							toast(getString(R.string.h1180));
							return;
						}
						model.setUid(IsMobileNumPhone.isUid());
						String guigeID = "";// 规格id
						List<String> xuanzhong = selectedGuige();
						// String xz=xuanzhong.toString();
						StringBuffer stringBuffer = new StringBuffer();
						if (xuanzhong != null) {
							for (String s1 : xuanzhong) {
								stringBuffer.append(s1 + ";");
							}
						}
						for (int sid = 0; sid < detailBean.getSku_list().size(); sid++) {
							String skuID = detailBean.getSku_list().get(sid)
									.getSku_id();
							String pkid = detailBean.getSku_list().get(sid)
									.getSku_pkid();
							if (skuID.equals(stringBuffer.toString())) {
								guigeID = pkid;
							}
						}
						// model.setSku_pkid(descid.substring(1,
						// descid.length()));
						model.setSku_pkid(guigeID);// 规格

						model.setId(detailBean.getId());
						model.setCount(moreCount.substring(1,
								moreCount.length()));
						shopCartPresenter.shopcartDuoAdd(model);
						dismiss();
					}
					dismiss();
				}
			});

		}

		public void onKucun() {

			for (int i = 0; i < detailBean.getSku_list().size(); i++) {
				detailBean.getSku_list().get(i).setSelected(false);
				// View view = LayoutInflater.from(GoodsDetail.this).inflate(
				// R.layout.item_detail_goods, null);

				price_m.setText(""
						+ PriceChange.Change(detailBean.getSku_list().get(i)
								.getPrice()
								+ ""));
				kucuns.setText(getString(R.string.h26) + ":"
						+ detailBean.getSku_list().get(i).getQuantity()
						+ detailBean.getSku_list().get(i).getUnit_name() + "");// 库存

				color_tv.setText(detailBean.getSku_list().get(i).getSku_desc()
						+ "");// 颜色
				jians.setTag(i);
				jias.setTag(i);
				inputs.setTag(i);

				hashMap.add(inputs);
				inputs.setOnClickListener(new OnClickListener() {

					@SuppressWarnings("deprecation")
					@Override
					public void onClick(final View v) {

						View view = LayoutInflater.from(GoodsDetail.this)
								.inflate(R.layout.goodsdetail_edit, null);
						TextView pop_ok = (TextView) view.findViewById(R.id.ok);
						final EditText pop_input = (EditText) view
								.findViewById(R.id.pop_input);

						pop_ok.setOnClickListener(new OnClickListener() {

							@SuppressWarnings("deprecation")
							@Override
							public void onClick(View view) {

								// inputs.setTextColor(getResources().getColor(
								// R.color.black));
								singleNum = pop_input.getText().toString() + "";
								try {
									if (Integer.parseInt(singleNum.equals("") ? "0"
											: singleNum) > Integer.parseInt(kc
											.equals("") ? "0" : kc)) {
										toast(getString(R.string.h28));
										return;
									} else if (Integer.parseInt(singleNum
											.equals("") ? "0" : singleNum) < Integer
											.parseInt(qp.equals("") ? "0" : qp)) {
										toast(getString(R.string.h1181));
										return;
									}
									inputs.setText(Integer.parseInt(singleNum
											.equals("") ? "0" : singleNum) + "");
									JiSuan(Integer.parseInt(singleNum
											.equals("") ? "0" : singleNum), v);
									popupWindow.dismiss();
								} catch (Exception e) {

									inputs.setText(0 + "");
								}
							}
						});
						popupWindow = new PopupWindow(view,
								LayoutParams.FILL_PARENT, ChangeToDP(145));
						popupWindow.setOutsideTouchable(false);
						popupWindow.setFocusable(true);
						popupWindow.setBackgroundDrawable(new BitmapDrawable());
						// popupWindow.showAsDropDown(v);
						int[] location = new int[2];
						v.getLocationOnScreen(location);
						popupWindow.showAtLocation(v, Gravity.NO_GRAVITY,
								location[0], location[1] - ChangeToDP(155));
					}
				});

				jians.setOnClickListener(new OnClickListener() {

					@SuppressWarnings("deprecation")
					@Override
					public void onClick(View v) {

						// DialogTopShow((int) v.getTag());
						inputs.setTextColor(getResources().getColor(
								R.color.black));
						String s = inputs.getText().toString();
						try {
							int c = Integer.parseInt(s.equals("") ? "0" : s);
							if (c > Integer.parseInt(qp.equals("") ? "0" : qp)) {
								c--;
							} else {
								toast(getString(R.string.h1181));
							}

							inputs.setText(c + "");
							JiSuan(c, v);
						} catch (Exception e) {

							inputs.setText(0 + "");
						}
					}

				});
				jias.setOnClickListener(new OnClickListener() {

					@SuppressWarnings("deprecation")
					@Override
					public void onClick(View v) {

						inputs.setTextColor(getResources().getColor(
								R.color.black));
						// DialogTopShow((int) v.getTag());
						try {
							String s = inputs.getText().toString();
							int c = Integer.parseInt(s.equals("") ? "0" : s);
							if (c < Integer.parseInt(kc.equals("0") ? "0" : kc)) {
								inputs.setText(c + 1 + "");
							} else {
								toast(getString(R.string.h28));
							}
							JiSuan(c + 1, v);
						} catch (Exception e) {

							inputs.setText(0 + "");
						}

					}
				});
				// guigeContainer.addView(view);
			}
		}

		public void close() {
			View v = getView().findViewById(R.id.container);
			ObjectAnimator animator = ObjectAnimator.ofFloat(v, "translationY",
					0, v.getHeight()).setDuration(300);
			animator.addListener(new AnimatorListener() {
				@Override
				public void onAnimationStart(Animator arg0) {
				}

				@Override
				public void onAnimationRepeat(Animator arg0) {
				}

				@Override
				public void onAnimationEnd(Animator arg0) {
					dismiss();
				}

				@Override
				public void onAnimationCancel(Animator arg0) {
					dismiss();
				}
			});
			animator.start();
		}

		/**
		 * 判断是否选中规格
		 * 
		 * @return
		 */
		protected String checkGuiGeSelectedState() {

			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < guigeContainer.getChildCount(); i++) {
				View vv = guigeContainer.getChildAt(i);
				if (!(vv instanceof FlowLayout)) {
					continue;
				}
				FlowLayout flowLayout = (FlowLayout) vv;
				int j;
				for (j = 0; j < flowLayout.getChildCount(); j++) {
					TextView textView = (TextView) flowLayout.getChildAt(j);
					if (textView.isSelected()) {
						sb.append(textView.getTag() + ";");
						break;
					}
				}
				if (j == flowLayout.getChildCount()) {
					// Toast.makeText(
					// getContext(),
					// "请选择"
					// + goodsDetailBeans.getSkuName().get(i / 2)
					// .getId(), 1).show();
					toast(getString(R.string.h1180));// 至少选择一个规格
					return null;
				}
			}
			return sb.toString();
		}

		// 规格
		private void addGuiGe() {

			List<GoodsDetailBean.SkuInfo> list = detailBean.getSku_info();
			for (int i = 0; i < list.size(); i++) {
				GoodsDetailBean.SkuInfo skuBean = list.get(i);
				TextView title = createTitle(skuBean.getSku_name());
				guigeContainer.addView(title);

				flowLayout = createFlowLayout(skuBean.getSku_id(), detailBean
						.getSku_info().get(i).getValue_list(), "");
				arFlowLayout.add(flowLayout);
				guigeContainer.addView(flowLayout);
			}
			container.getViewTreeObserver().addOnGlobalLayoutListener(
					new ViewTreeObserver.OnGlobalLayoutListener() {

						@SuppressWarnings("deprecation")
						@SuppressLint("NewApi")
						@Override
						public void onGlobalLayout() {
							try {
								container.getViewTreeObserver()
										.removeGlobalOnLayoutListener(this);
							} catch (Throwable e) {
							}
							if (container.getHeight() > DensityUtil
									.screenHeigh() * 0.7) {

								int h = DensityUtil.screenHeigh()
										- DensityUtil.dip2px(280);
								XScrollView scrollView = new XScrollView(
										getActivity());
								scrollView
										.setLayoutParams(new ViewGroup.LayoutParams(
												ViewGroup.LayoutParams.MATCH_PARENT,
												h));

								ViewGroup vg = (ViewGroup) guigeContainer
										.getParent();
								vg.removeView(guigeContainer);

								scrollView.addView(guigeContainer);
								vg.addView(scrollView);
							}
						}
					});
		}

		private View.OnClickListener clickListener = new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				if (v.isSelected()) {
					v.setSelected(false);
					((TextView) v).setTextColor(Color.BLACK);
					imgUrl = detailBean.getMain_img();
					if ((!detailBean.getMain_img().equals(""))
							& detailBean.getMain_img() != null) {
						XImageLoader.load(GlobalConfig.IMAGE_DOUBLE
								+ detailBean.getMain_img(), pic);
						XImageLoader.load(GlobalConfig.IMAGE_DOUBLE
								+ detailBean.getMain_img(), pic);
					}
					// txt_price.setText("");
					return;
				}
				FlowLayout clickTextViewParent = null;
				StringBuilder stringBuilder = new StringBuilder();

				for (int i = 0; i < guigeContainer.getChildCount(); i++) {
					View view = guigeContainer.getChildAt(i);
					if (!(view instanceof FlowLayout)) {
						continue;
					}
					FlowLayout flowLayout = (FlowLayout) view;
					if (v.getParent() == flowLayout) {
						clickTextViewParent = flowLayout;
						stringBuilder.append(v.getTag());
						stringBuilder.append(";");

					} else {
						for (int j = 0; j < flowLayout.getChildCount(); j++) {
							View textview = flowLayout.getChildAt(j);
							if (textview.isSelected()) {
								stringBuilder.append(textview.getTag());
								stringBuilder.append(";");
								break;
							}
						}
					}
				}
				List<GoodsDetailBean.SkuInfo> skuList = detailBean
						.getSku_info();
				String selectedSku = stringBuilder.toString();
				for (int i = 0; i < skuList.size(); i++) {
					String sku = skuList.get(i).getSku_id();
					for (int j = 0; j < clickTextViewParent.getChildCount(); j++) {
						if (clickTextViewParent.getChildAt(j).isSelected()) {
							clickTextViewParent.getChildAt(j)
									.setSelected(false);
							((TextView) clickTextViewParent.getChildAt(j))
									.setTextColor(Color.BLACK);
							break;
						}
					}
					v.setSelected(true);
					// txt_price.setText(Double.parseDouble(v.getTag(R.id.tag_first)+"")/100+"元/"+goodsDetailBeans.getGoods_unit_name());
					((TextView) v).setTextColor(Color.WHITE);
				}
				String s = isAllFenLeiSelected();
				if (s != null) {
					// ((View) kucun.getParent()).setVisibility(View.VISIBLE);
					List<GoodsDetailBean.A> list = detailBean.getSku_list();
					for (GoodsDetailBean.A skuCombinationBean : list) {
						if (skuCombinationBean.getSku_id().equals(s)) {

							if (TextUtils.isEmpty(skuCombinationBean
									.getIcon_url())) {
								XImageLoader.load(GlobalConfig.IMAGE_DOUBLE
										+ detailBean.getMain_img(), pic);
							} else {
								XImageLoader
										.load(GlobalConfig.IMAGE_DOUBLE
												+ skuCombinationBean
														.getIcon_url(), pic);
							}

							kc = skuCombinationBean.getQuantity();
							qp = skuCombinationBean.getCnt1();
							jg = skuCombinationBean.getPrice();
							dw = skuCombinationBean.getUnit_name();
							tx = skuCombinationBean.getIcon_url();
							kucuns.setText(getString(R.string.h26) + ":" + kc
									+ dw + "");// 库存
							qipi.setText("(" + qp + dw + "起批)");
							price.setText(PriceChange.Change(jg));// 价格
							unit.setText("/" + dw);
							inputs.setText(qp);
							total_num1.setText(dw);
							break;
						}
					}
				} else {
					// ((View) kucun.getParent())
					// .setVisibility(View.INVISIBLE);
				}
				// } catch (Exception e) {
				// ByAlert.alert(e.getMessage());
				// e.printStackTrace();
				// }
			}
		};

		private String isAllFenLeiSelected() {
			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < guigeContainer.getChildCount(); i++) {
				View vv = guigeContainer.getChildAt(i);
				if (!(vv instanceof FlowLayout)) {
					continue;
				}
				FlowLayout flowLayout = (FlowLayout) vv;
				int j;
				for (j = 0; j < flowLayout.getChildCount(); j++) {
					TextView textView = (TextView) flowLayout.getChildAt(j);
					if (textView.isSelected()) {
						sb.append(textView.getTag() + ";");
						break;
					}
				}
				if (j == flowLayout.getChildCount()) {
					return null;
				}
			}
			return sb.toString();
		}

		/**
		 * 当前已选中的规格集合
		 * 
		 * @return
		 */
		protected List<String> selectedGuige() {

			List<String> selectedGuige = new ArrayList<String>();
			for (int i = 0; i < guigeContainer.getChildCount(); i++) {
				View vv = guigeContainer.getChildAt(i);
				if (!(vv instanceof FlowLayout)) {
					continue;
				}
				FlowLayout flowLayout = (FlowLayout) vv;
				for (int j = 0; j < flowLayout.getChildCount(); j++) {
					TextView textView = (TextView) flowLayout.getChildAt(j);
					if (textView.isSelected()) {
						selectedGuige.add((String) textView.getTag());
					}
				}
			}
			return selectedGuige;
		}

		private FlowLayout createFlowLayout(String vid,
				List<GoodsDetailBean.ValueList> id, String str) {
			int dis = DensityUtil.dip2px(5);
			FlowLayout flowLayout = new FlowLayout(getActivity());
			for (int i = 0; i < id.size(); i++) {
				TextView textView = new TextView(getActivity());
				textView.setTextColor(Color.BLACK);
				textView.setBackgroundResource(R.drawable.selector_guige);
				textView.setText(id.get(i).getValue_name());
				textView.setTag(vid + ":" + id.get(i).getValue_id());
				textView.setTag(R.id.tag_first, detailBean.getSku_list().get(i)
						.getPrice());
				textView.setOnClickListener(clickListener);
				if (tempSkuId != null) {
					String[] strTemp = tempSkuId.split(";");
					for (String s : strTemp) {
						if (s.equals(textView.getTag().toString())) {
							textView.setSelected(true);
						}
					}

				}
				ViewGroup.MarginLayoutParams marginLayoutParams = new ViewGroup.MarginLayoutParams(
						ViewGroup.LayoutParams.WRAP_CONTENT,
						ViewGroup.LayoutParams.WRAP_CONTENT);
				marginLayoutParams.setMargins(dis, dis, dis, dis);
				textView.setLayoutParams(marginLayoutParams);
				flowLayout.addView(textView);
			}
			return flowLayout;
		}

		/**
		 * 设置套餐一、套餐二等标题栏
		 * 
		 * @param s
		 * @return
		 */
		private TextView createTitle(String s) {
			TextView textView = new TextView(getActivity());
			textView.setText(s);
			textView.setTextColor(Color.BLACK);
			return textView;
		}

		private void JiSuan(int c, View v) {
			myTotalp = PriceChange.Change(detailBean.getSku_list()
					.get((int) v.getTag()).getPrice());
			if (detailBean.getSku_list().size() != 0
					&& !"".equals(detailBean.getSku_list()
							.get((int) v.getTag()).getCnt2())
					&& !"0".equals(detailBean.getSku_list()
							.get((int) v.getTag()).getCnt2())
					&& detailBean.getSku_list().get((int) v.getTag()).getCnt2() != null) {

				if (!"".equals(detailBean.getSku_list().get((int) v.getTag())
						.getCnt3())
						&& !"0".equals(detailBean.getSku_list()
								.get((int) v.getTag()).getCnt3())) {
					if (Integer.parseInt(detailBean.getSku_list()
							.get((int) v.getTag()).getCnt2()) <= c
							&& c < Integer.parseInt(detailBean.getSku_list()
									.get((int) v.getTag()).getCnt3())) {
						myTotalp = PriceChange.Change(detailBean.getSku_list()
								.get((int) v.getTag()).getPrice2());
						price.setText(PriceChange.Change(detailBean
								.getSku_list().get((int) v.getTag())
								.getPrice2()));
					} else if (Integer.parseInt(detailBean.getSku_list()
							.get((int) v.getTag()).getCnt3()) <= c) {
						myTotalp = PriceChange.Change(detailBean.getSku_list()
								.get((int) v.getTag()).getPrice3());
						price.setText(PriceChange.Change(detailBean
								.getSku_list().get((int) v.getTag())
								.getPrice3()));
					} else {
						myTotalp = PriceChange.Change(detailBean.getSku_list()
								.get((int) v.getTag()).getPrice());
						price.setText(PriceChange.Change(detailBean
								.getSku_list().get((int) v.getTag()).getPrice()));
					}

				}
			}
			total = 0;
			totalNum = 0;
			DecimalFormat df = new DecimalFormat("######0.00");
			// for (int j = 0; j < hashMap.size(); j++) {
			// total += Double.parseDouble(myTotalp.substring(1,
			// myTotalp.length()))
			// * Integer.parseInt(hashMap.get(0).getText().toString() + "");
			total = Double.parseDouble(df.format(Double.parseDouble(jg) / 100))
					* Integer
							.parseInt(hashMap.get(0).getText().toString() + "");

			totalNum += Integer.parseInt(hashMap.get(0).getText().toString()
					+ "");
			// }
			detailBean.getSku_list().get((int) v.getTag()).setSelected(true);
			total_price.setText(df.format(total));
			total_num2.setText("" + totalNum);
		}

		private void TransportData(Intent intent) {
			clearAllList();
			DetailBean bean = new DetailBean();
			descid = new StringBuffer();
			for (int i = 0; i < detailBean.getSku_list().size(); i++) {
				if (detailBean.getSku_list().get(i).isSelected() == true) {
					descid.append(","
							+ detailBean.getSku_list().get(i).getSku_pkid());
					pricelist.add(detailBean.getSku_list().get(i).getPrice());
					codelist.add(detailBean.getSku_list().get(i)
							.getProduct_code());
					guigelist
							.add(detailBean.getSku_list().get(i).getSku_desc());
					imglist.add(detailBean.getSku_list().get(i).getSku_pkid());

					singleNum = inputs.getText().toString() + "";
					if ("order".equals(type)) {

					} else {

						if (Integer.parseInt(singleNum.equals("") ? "0"
								: singleNum) > Integer
								.parseInt(kc.equals("") ? "0" : kc)) {
							toast(getString(R.string.h28));
							return;
						} else if (Integer.parseInt(singleNum.equals("") ? "0"
								: singleNum) < Integer
								.parseInt(qp.equals("") ? "0" : qp)) {
							toast(getString(R.string.h1181));
							return;
						}

					}
				} else {
				}
			}
			for (int j = 0; j < hashMap.size(); j++) {
				if (detailBean.getSku_list().get(j).isSelected() == true) {
					countlist.add(hashMap.get(j).getText() + "");
				}

			}

			if (codelist.size() == 0) {
				toast(getString(R.string.h1180));
				return;
			}
			//bean.setUnit(detailBean.getGoods_unit_name());
			bean.setUnit(dw);
			bean.setChandi(detailBean.getPlace_origin());
			bean.setName(detailBean.getContact_name());
			bean.setGoodsname(detailBean.getName());
			bean.setSecondline(detailBean.getSecondary());
			bean.setSingle_price(pricelist);
			bean.setFaburen((detailBean.getContact_name()));
			bean.setTotal(total + "");
			bean.setCode(codelist);
			bean.setCount(countlist);
			bean.setDesc(guigelist);
			bean.setImg(imglist);
			bean.setJg(jg);
			bean.setTx(tx);
			bean.setId(detailBean.getId());
			if (countlist.size() == 1 && "0".equals(countlist.get(0))) {
				return;
			}

			bean.setPskid(descid.substring(1, descid.length()));
			intent.putExtra("detail", bean);
			startActivity(intent);
		}

		private void clearAllList() {
			pricelist.clear();
			codelist.clear();
			guigelist.clear();
			countlist.clear();
			imglist.clear();
			codelist.clear();
		}

	}
}
